﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library
{
    class DalHoaDonNhap
    {
        internal static List<HoaDonNhap> GetList()
        {
            List<HoaDonNhap> result = new List<HoaDonNhap>();

            QLDCTTEntities da = new QLDCTTEntities();

            try
            {
                result = da.HoaDonNhap.ToList();
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }

        internal static List<HoaDonNhap> GetListByNgay(DateTime fromDate, DateTime toDate, List<HoaDonNhap> lst)
        {
            List<HoaDonNhap> result = new List<HoaDonNhap>();

            QLDCTTEntities da = new QLDCTTEntities();

            try
            {
                result = (from dh in lst
                          where dh.Ngay >= fromDate && dh.Ngay <= toDate
                          select dh).ToList();
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }

        internal static void Add(HoaDonNhap bizhdn)
        {
            try
            {
                HoaDonNhap hdn = new HoaDonNhap();
                hdn.MaHDN = bizhdn.MaHDN;
                hdn.MaNV = bizhdn.MaNV;
                hdn.TenNCC = bizhdn.TenNCC;
                hdn.Ngay = bizhdn.Ngay;
                hdn.ThanhTien = bizhdn.ThanhTien;

                QLDCTTEntities entities = new QLDCTTEntities();
                entities.HoaDonNhap.Add(hdn);

                entities.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
